package com.fenghen.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.fenghen.common.annotation.Log;
import com.fenghen.common.enums.BusinessType;
import com.fenghen.system.domain.RiskIdentification;
import com.fenghen.system.service.IRiskIdentificationService;
import com.fenghen.common.core.controller.BaseController;
import com.fenghen.common.core.domain.AjaxResult;
import com.fenghen.common.utils.poi.ExcelUtil;
import com.fenghen.common.core.page.TableDataInfo;

/**
 * 风险识别模块Controller
 * 
 * @author fenghen
 * @date 2024-11-06
 */
@Controller
@RequestMapping("/system/identification")
public class RiskIdentificationController extends BaseController
{
    private String prefix = "system/identification";

    @Autowired
    private IRiskIdentificationService riskIdentificationService;

    @RequiresPermissions("system:identification:view")
    @GetMapping()
    public String identification()
    {
        return prefix + "/identification";
    }

    /**
     * 查询风险识别模块列表
     */
    @RequiresPermissions("system:identification:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RiskIdentification riskIdentification)
    {
        startPage();
        List<RiskIdentification> list = riskIdentificationService.selectRiskIdentificationList(riskIdentification);
        return getDataTable(list);
    }

    /**
     * 导出风险识别模块列表
     */
    @RequiresPermissions("system:identification:export")
    @Log(title = "风险识别模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RiskIdentification riskIdentification)
    {
        List<RiskIdentification> list = riskIdentificationService.selectRiskIdentificationList(riskIdentification);
        ExcelUtil<RiskIdentification> util = new ExcelUtil<RiskIdentification>(RiskIdentification.class);
        return util.exportExcel(list, "风险识别模块数据");
    }

    /**
     * 新增风险识别模块
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存风险识别模块
     */
    @RequiresPermissions("system:identification:add")
    @Log(title = "风险识别模块", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RiskIdentification riskIdentification)
    {
        return toAjax(riskIdentificationService.insertRiskIdentification(riskIdentification));
    }

    /**
     * 修改风险识别模块
     */
    @RequiresPermissions("system:identification:edit")
    @GetMapping("/edit/{riskId}")
    public String edit(@PathVariable("riskId") Long riskId, ModelMap mmap)
    {
        RiskIdentification riskIdentification = riskIdentificationService.selectRiskIdentificationByRiskId(riskId);
        mmap.put("riskIdentification", riskIdentification);
        return prefix + "/edit";
    }

    /**
     * 修改保存风险识别模块
     */
    @RequiresPermissions("system:identification:edit")
    @Log(title = "风险识别模块", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RiskIdentification riskIdentification)
    {
        return toAjax(riskIdentificationService.updateRiskIdentification(riskIdentification));
    }

    /**
     * 删除风险识别模块
     */
    @RequiresPermissions("system:identification:remove")
    @Log(title = "风险识别模块", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(riskIdentificationService.deleteRiskIdentificationByRiskIds(ids));
    }
}
